package com.example.init.controller;

import com.example.init.Person;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

//@RestController
@Controller
@RequestMapping("/return")
public class ReturnController {

    @RequestMapping("/index")
    public String returnIndex(){
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("/returnData")
    public String returnData(){
        return "返回视图需要的数据";
    }

    @ResponseBody
    @RequestMapping("/returnHtml")
    public String returnHtml(){
        return "<h1>返回代码片段<1>";
    }

    @ResponseBody
    @RequestMapping("/returnJson")
    public Person returnJson(){
        Person person = new Person(1,"wen");

        return person;
    }
    @ResponseBody
    @RequestMapping("/returnMap")
    public HashMap<Integer,String> returnMap(){
        HashMap<Integer,String> map = new HashMap<>();
        map.put(12,"wen");
        return map;
    }

    @ResponseBody
    @RequestMapping("/setStatus")
    public String setStatus(HttpServletResponse response){
        response.setStatus(401);
        return "设置状态码";
    }

    @RequestMapping(value = "setHeader",produces = "application/json")
    @ResponseBody
    public String setHeader(){
        return "{\"success\":true}";
    }


}
